<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        .box {
            width: 400px;
            height: 300px;
            background-color:azure;
            margin: 100px auto;
        }

        .box .mingzi {
            text-align: center;
            font-weight: bold;
            font-size: 20px;
        }

        .box div {
            margin-top: 20px;
        }

        .box .zz {
            margin-left: 50px;
        }

        input {
            width: 300px;
            height: 30px;
            outline: none;
            border-radius: 5px;
            border: 1px solid;
        }

        .an input {
            margin: 0 50px;
            background-color: blue;
            color: white;
        }
    </style>
</head>


<body>
    <div class="box">
        <div class="mingzi">登录页面</div>
        <div class="zz"><input type="text" placeholder="手机号/用户名/邮箱"></div>
        <div class="zz"> <input type="password" placeholder="密码" name="" id=""></div>
        <div class="an"><input type="button" value="登录"></div>
    </div>
</body>

</html>
<script src="./ajax.js"></script>
<script>
    var input = document.querySelectorAll('.box input')

    input[2].onclick = function () {
        if (input[0].value && input[1].value) {
            if (/^\d{4}$/.test(input[1].value)) {
                ajax('get', 'https://yantianfeng.com/api/login', { username: input[0].value, password: input[1].value }, function (data) {
                    console.log(data);
                    if( data.status == 200 ){
                            alert('登陆成功');
                        }else{
                            alert('登录失败');
                        }
                })
            } else {
                alert('请输入正确的手机号/密码')
            }
        } else {
            alert('用户名/密码不能为空')
        }
    }

</script>